"""
    Author:
    Date: 2018-11-08

    微信管理后台-服务器监控
"""

from django.shortcuts import render

from entities import server_mgr

from .. import helpers
from .. helpers import gma_login_required


@gma_login_required
def index(request):
    """ 代理管理首页 """
    context = helpers.build_context(request)
    return render(request, 'gma/monitor/monitor_home.html', context)


@gma_login_required
def api_server_log_list(request):
    """ 显示ApiServer的日志列表 """
    files = server_mgr.get_api_server_log_files()
    context = helpers.build_context(request)
    context['files'] = files
    return render(request, 'gma/monitor/api_server_log_list.html', context)


@gma_login_required
def api_server_log(request, log_name):
    """ 显示ApiServer的指定的日志内容 """
    logs = server_mgr.get_api_server_log(log_name, 200)
    context = helpers.build_context(request)
    context['logs'] = logs
    return render(request, 'gma/monitor/api_server_log.html', context)


if __name__ == '__main__':
    print('ok')
